package rig.com.autoconfigure.config;

import lombok.Data;
import lombok.ToString;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import rig.com.autoconfigure.SnowflakeFactory;

/**
 * @author MShaoJie
 * @create 2021/8/24 8:32
 **/
@ToString
@Data
@EnableAutoConfiguration(exclude = {SnowflakeProperties.class})
@ConfigurationProperties(prefix = SnowflakeProperties.PREFIX)
public class SnowflakeProperties {

    public static final String PREFIX = "rig.snowflake";

    private Integer datacenterId;

    private Integer machineId;

    @Bean
    @Lazy
    public SnowflakeFactory getSnowflakeFactory() {
        SnowflakeFactory snowflakeFactory = new SnowflakeFactory(datacenterId, machineId);
        return snowflakeFactory;
    }
}